To display user input, code, and program outputs, we have specific elements in HTML5.
HTML <kbd> Element
<kbd> stand for keyboard, and it is used to represent keyboard shortcut keys and other input or voice commands. The bowser show <kbd> content in monospace font style.
Example
Output
HTML <samp> Element
The <samp> element is used to define the computing or ouput result of a program . It is similar to <kbd> element and display its content in monospace font style.
Example
Output
The entered value is not a number
HTML <code> element
As its name suggests, <code> element is used to display code text in the web browser. It does not preserve the whitespace between its content, which mean if you have provided more than one space between its content, then it would be replaced by single space.
Example
Output
To preserve the white spacing and new line use <pre> or preformatted element.
Example
HTML <var> Element
The <var> element is used to represent mathematical variables on the document. Generally all the mathematical expression represented using <var> element.
Example
Output
HTML computer Code Elements Quick Summary
- HTML5 has some elements to represent coding and computer text.
- <kbd> element is used to represent input and output text.
- <code> is used to represent the code of a programming language.
- <samp> element represent single outputs.
- <var> variable represents mathematic variables.